#include<bits/stdc++.h>
using namespace std;
const int N=2e+5;
long long t,n,a[N],c;
long long f[N];
bool fl[N];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        c=0;
        cin>>n;
        for(int j=1;j<=n;j++){
            cin>>a[j];
            f[a[j]]+=1;
        }
        for(int j=1;j<=n;j++){
            if(f[a[j]]>=2&&fl[a[j]]==0){
                c+=a[j];
                fl[a[j]]=1;
            }
        }
        cout<<c<<endl;
        for(int j=1;j<=n;j++){
            f[a[j]]=0;
            fl[a[j]]=0;
        }
    }
    
    return 0;
}